export default {
    props: {
        initFiltersByRouteQuery: Boolean, //是否根据路由参数初始化搜索框
        searchLabelWidth: String, //搜索框label宽度
        filters: { type: Array, default: () => [] } //自定义筛选项
    },
    data() {
        return {
            search: {
                visible: false,
                value: {}
            }
        }
    },
    computed: {
        isSearchEmpty() {
            return Object.values(this.search.value).every(value => value !== 0 && !value)
        },
        showSearch() {
            return this.filters.length > 0
        }
    },
    methods: {
        onSearch(filter) {
            this.table.pageNo = 1
            this.search.value = {...filter }
            this.$refs.searchDrawer.closeDrawer()
            this.loadTable()
        },
        searchOnClick() {
            this.search.visible = true

            this.$nextTick(() => this.$refs.search.initForm(this.search.value))
        },
        initFilterByRoute() {
            if (this.initFiltersByRouteQuery !== true) {
                return
            }

            this.filters.forEach(filter => {
                if (filter.prop2) {
                    filter.value2 = this.$route.query[filter.prop2] || ''
                    this.search.value[filter.prop2] = filter.value2
                }
                filter.value = this.$route.query[filter.prop] || ''
                this.search.value[filter.prop] = filter.value
            })

            this.search.value = {...this.search.value }
        }
    }
}